home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Libris Britannia 4
/
science library(b).zip
/
science library(b)
/
DDJMAG
/
DDJ9110.ZIP
/
STRING.ZIP
/
STRIINS1.CPP
< prev
next >
Wrap
C/C++ Source or Header
|
1991-07-30
|
705b
|
31 lines
#include <string.h>
#include <ctype.h>
#include <errno.h>
#include <string.hpp>
String &String::insert(int pos, const String &a)
{
if (!a.length())
return *this;
if (pos > length()) { // pos == length() is concatenate
errno = ERANGE;
return *this;
}
int n = length()+a.length();
srep *p = new(n) srep(n);
if (!p) {
errno = ENOMEM;
return *this;
}
memmove(p->body,body(),pos);
memmove(p->body+pos, a.body(), a.length());
memmove(p->body+pos+a.length(), body()+pos, length()-pos);
if (rp) {
if (--rp->refs < 1)
delete rp;
}
rp = p;
rp->refs++;
return *this;
}